package com.nnfe.fyd.base;

import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.nnfe.fyd.R;
import com.nnfe.fyd.http.RetrofitInterface;
import com.nnfe.fyd.http.RetrofitSingleton;
import com.nnfe.fyd.view.ActionBarView;

/**
 * ----------------------------------
 * Created by xyd on 2017/3/15.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */
public abstract class ActionBarFragment extends BaseFragment implements ActionBarView.ActionBarListener {

    /**
     * 标题栏
     */
    protected ActionBarView mActionBar;
    public RetrofitInterface service;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_base, container, false);
        CoordinatorLayout  frameLayout= (CoordinatorLayout) root.findViewById(R.id.body);
        if (getContentView() != 0) {
            View contentView = inflater.inflate(getContentView(), root, false);
            frameLayout.addView(contentView);
        }

        mActionBar = (ActionBarView) root.findViewById(R.id.actionbar_title);
        mActionBar.setTitle(getTitleString());
        //左键监听
        mActionBar.getLeftButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onLeftButtonClick();
            }
        });
        //右键监听
        mActionBar.getRightButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onRightButtonClick();
            }
        });

        initLeftButton(mActionBar.getLeftButton());
        initRightButton(mActionBar.getRightButton());

        service = RetrofitSingleton.getService(mContext);

        return root;
    }

    protected void initView(){};

    // =================↓ actionBar==================
    @Override
    public void onLeftButtonClick() {
        mContext.onBackPressed();
    }

    @Override
    public void onRightButtonClick() {

    }

    @Override
    public void initLeftButton(Button leftButton) {

    }

    @Override
    public void initRightButton(Button rightButton) {

    }

    public void setTitle(Object obj) {
        mActionBar.setTitle(obj);
    }

    // =================↑ actionBar ==================

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

}